#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
//       int sigaction(int signum, const struct sigaction *act,
//                     struct sigaction *oldact);


void handler(int signum, siginfo_t *info, void *context){

	if(signum == SIGUSR1){
		printf("SIGUSR1 signum is %d\n",signum);
	}
	else if(signum == SIGUSR2){
                printf("SIGUSR2 signum is %d\n",signum);
	}
	else{
		printf("error!\n");
	}
	if(context){
	
		printf("from pid:%d\n",info->si_pid);
                printf("from %d\n",signum);
		printf("data is %d\n",info->si_int);
		printf("content is %d\n",info->si_value.sival_int);
	}
}


int main(){

	struct sigaction act;

	/*
	struct sigaction {
	void     (*sa_handler)(int);
	void     (*sa_sigaction)(int, siginfo_t *, void *);
	sigset_t   sa_mask;
	int        sa_flags;
	};
	*/

	printf("My PID is %d\n",getpid());

	act.sa_flags = SA_SIGINFO;
	act.sa_sigaction = handler;
	sigaction(SIGUSR1,&act,NULL);
	sigaction(SIGUSR2,&act,NULL);
	while(1);
}
